﻿<%@ Page Title="" Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Configuration" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" >
    <title>Form spese</title>

    <meta name="viewport" content="initial-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <!-- style sheets -->
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
    <link rel="stylesheet" href="./css/TimereportMobile.css" />
    <!-- jquery mobile -->
    <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="./js/customscript.js"></script>
    <!-- bottone back su sottomenu -->
    <script>
            $(document).bind("mobileinit", function () {
                $.mobile.page.prototype.options.addBackBtn = true;
            });
    </script>
    <script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
    <script type="text/javascript" src="./js/jquery.validate.js"></script
    <!-- jquery mobile FINE -->
    <script>
    <!-- elimina barra -->   
            var iWebkit; if (!iWebkit) { iWebkit = window.onload = function () { function fullscreen() { var a = document.getElementsByTagName("a"); for (var i = 0; i < a.length; i++) { if (a[i].className.match("noeffect")) { } else { a[i].onclick = function () { window.location = this.getAttribute("href"); return false } } } } function hideURLbar() { window.scrollTo(0, 0.9) } iWebkit.init = function () { fullscreen(); hideURLbar() }; iWebkit.init() } }
     // popola dropdown TipoOre                          
     </script>

     <script type="text/javascript" language="javascript">
        
            $(document).ready(function () {

            $.ajax({
                type: "POST",
                url: "aggiorna.asmx/GetTipoOreList",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: "",
                success: function(response) {
                    var ddl1 = ( response.d == undefined ) ? response : response.d; // compatibilità ASP.NET 2.0
                    for (var i = 0; i < ddl1.length; i++) {
                        var selectOption = $(document.createElement('option'));
                        $('#ore_TipoOre_Id').append(selectOption.val(ddl1[i].TipoOreId).html(ddl1[i].TipoOreName) );
                    }
                    $("#ore_TipoOre_Id").val("1"); // default
                    },
                error: function(xhr, textStatus, errorThrown){
                        alert(xhr.responseText); }
             });

              // popola dropdown Progetti

              $.ajax({
                type: "POST",
                url: "aggiorna.asmx/GetProjectsList",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: "{'Person_id': '" + <%= Request.QueryString["id"] %> + "'}",
                success: function(response) {
                    var ddl1 = ( response.d == undefined ) ? response : response.d; // compatibilità ASP.NET 2.0
                    for (var i = 0; i < ddl1.length; i++) {
                        var selectOption = $(document.createElement('option'));
                        var ore_selectOption = $(document.createElement('option'));
                        $('#Projects_Id').append(selectOption.val(ddl1[i].ProjectId).html(ddl1[i].ProjectName) );
                        $('#ore_Projects_Id').append(ore_selectOption.val(ddl1[i].ProjectId).html(ddl1[i].ProjectName) );
                    }
                    },
                error: function(xhr, textStatus, errorThrown){
                        alert(xhr.responseText); }
             });

             // popola spese
   
             $.ajax({
                type: "POST",
                url: "aggiorna.asmx/GetSpeseList",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: "{'Person_id': '" + <%= Request.QueryString["id"] %> + "'}",
                success: function(response) {
                    var ddl2 = ( response.d == undefined ) ? response : response.d; // compatibilità ASP.NET 2.0
                    for (var i = 0; i < ddl2.length; i++) {
                        var selectOption = $(document.createElement('option'));
                        $('#Spese_Id').append(selectOption.val(ddl2[i].SpeseId).html(ddl2[i].SpeseName) );
                    }
                    },
                error: function(xhr, textStatus, errorThrown){
                        alert(xhr.responseText); }
             });


                $("#SpeseForm").validate({
                rules: {
                          Tbdate: {required: true, date: false },
                          TbExpenseAmount: {required: true, number: true},
                        },
                messages: {
                          Tbdate: {required: "Inserire un valore!" },
                          TbExpenseAmount: {required: "Inserire un valore!", number: "Campo numerico!"},
                        },
                 submitHandler: function() {
                    SpeseSubmit();
                    return false ;
                 }
            }) // spese validate

               $("#OreForm").validate({
                rules: {
                          TbdateForHours: {required: true, date: false },
                          TbHours: {required: true, number: true},
                        },
                messages: {
                          TbdateForHours: {required: "Inserire un valore!" },
                          TbHours: {required: "Inserire un valore!", number: "Campo numerico!"},
                        },
                 submitHandler: function() {
                    OreAjaxSubmit();
                    return false ;
                 }                
              }) // ore validate
              
            }); // document ready

            function SpeseSubmit() { 

                     var values = "{'Tbdate': '" + $('#Tbdate').val() + "'" + 
                               ", 'TbExpenseAmount': '" + $('#TbExpenseAmount').val() + "'" +
                              ", 'Person_id': '" + <%= Request.QueryString["id"] %> + "'" + 
                               " , 'Projects_Id': '" + $('#Projects_Id').val() + "'" + 
                               " , 'ExpenseType_Id': '" + $('#Spese_Id').val() + "'" + 
                               " , 'comment': '" + $('#comment').val() + "'" + 
                               " , 'CreditCardPayed': '" + $('#CreditCardPayed').is(':checked') + "'" +
                               " , 'CancelFlag': '" + $('#CancelFlag').is(':checked') + "'" + 
                               " , 'InvoiceFlag': '" + $('#InvoiceFlag').is(':checked') + "'" + 
                               "}"; 
        
                    $.mobile.showPageLoadingMsg("a", "Aggiornamento", true);

                    $.ajax({
                        type: "POST",
                        url: "aggiorna.asmx/salvaspese",
                        data: values,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function(msg) {  
                        SpeseSucceeded(msg); },   
                        error: function(xhr, textStatus, errorThrown){
                           alert(xhr.responseText); }
                    }); // ajax
             }

            function SpeseSucceeded(msg) {                        
            // pulisci campi modulo
               $('#TbExpenseAmount').val("");
               $('#comment').val("");
               $('#CreditCardPayed').attr('checked',false); 
               $('#CancelFlag').attr('checked',false);
               $('#InvoiceFlag').attr('checked',false);
               $('#CreditCardPayed').checkboxradio("refresh");
               $('#CancelFlag').checkboxradio("refresh");
               $('#InvoiceFlag').checkboxradio("refresh");

              $.mobile.hidePageLoadingMsg();
            
            // chiamata con successo analizza risposta
               if (msg == "true" || msg.d == "true") {
                    $('#toptitle').html('Aggiornamento Effettuato');
                    $("#toptitle").fadeOut(1000, function () {
                        $(this).text("Inserisci Spese")
                    }).fadeIn();
                     } 
                     else
                    {
                    alert('Errore in aggiornamento: ' + msg ); // errore
                    }  
            }
            
//            function AjaxFailed(result) {
//                $.mobile.hidePageLoadingMsg();
//                alert(result.status + ' >> ' + result.responseText);
//            } 

             function OreAjaxSubmit() { 

                     var values = "{'TbdateForHours': '" + $('#ore_TbdateForHours').val() + "'" + 
                               ", 'TbHours': '" + $('#ore_TbHours').val() + "'" +
                              ", 'Person_id': '" + <%= Request.QueryString["id"] %> + "'" + 
                               " , 'Projects_Id': '" + $('#ore_Projects_Id').val() + "'" + 
                               " , 'HourType_Id': '" + $('#ore_TipoOre_Id').val() + "'" + 
                               " , 'comment': '" + $('#ore_comment').val() + "'" + 
                               " , 'TransferFlag': '" + $('#ore_TransferFlag').is(':checked') + "'" +
                               " , 'CancelFlag': '" + $('#ore_CancelFlag').is(':checked') + "'" + 
                               "}";
        
                    $.mobile.showPageLoadingMsg("a", "Aggiornamento", true);

                    $.ajax({
                        type: "POST",
                        url: "aggiorna.asmx/salvaore",
                        data: values,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function(msg) {  
                        OreAjaxSucceeded(msg); },   
                        error: function(xhr, textStatus, errorThrown){
                           alert(xhr.responseText); }
                    }); // ajax
             }

            function OreAjaxSucceeded(msg) {                        
            // pulisci campi modulo
               $('#ore_TbHours').val("");
               $('#ore_comment').val("");
               $('#ore_TransferFlag').attr('checked',false); 
               $('#ore_CancelFlag').attr('checked',false);
               $('#ore_TransferFlag').checkboxradio("refresh");
               $('#ore_CancelFlag').checkboxradio("refresh");

              $.mobile.hidePageLoadingMsg();
            
            // chiamata con successo analizza risposta
               if (msg == "true" || msg.d == "true") {
                    $('#ore_toptitle').html('Aggiornamento Effettuato');
                    $("#ore_toptitle").fadeOut(1000, function () {
                        $(this).text("Inserisci Ore")
                    }).fadeIn();
                     } 
                     else
                    {
                    alert('Errore in aggiornamento: ' + msg ); // errore
                    }  
            }

        </script>

</head>
    
<body>
    <div data-role="page" data-dom-cache="true" id="mainmenu">
        <div data-role="header" data-position="fixed">
            <a href='./login.aspx' class='ui-btn-left' data-icon='back'  rel="external">Logoff</a>
            <h1>Menu</h1>
        </div>
        <!-- /header -->
        <div data-role="content">
            <ul data-role="listview" data-inset="true">
                <li><a href="#FormSpesePage">
                    <img src="./images/money.png" / >
                    <h3>Spese</h3>
                    <p>Inserisci spese</p>  
                </a></li>
                <li><a href="#FormOrePage"   > 
                    <img src="./images/clock_128.png" />
                    <h3>Ore</h3>
                    <p>Inserisci ore
                    </p>
                </a></li>
                <li><a href="index.html">
                    <img src="./images/report_check.png" />
                    <h3>Report</h3><p> Ore e spese per mese corrente e precedente</p></a>
                    <ul  data-role="listview" data-inset="true">
							<li><a href="list-spese.aspx?id=<%= Request.QueryString["id"] %>"><img src="./images/money.png" /><h3>Report Spese</h3><p>Report spese mese corrente e precedente</p></a></li>
							<li><a href="list-ore.aspx?id=<%= Request.QueryString["id"] %>"><img src="./images/clock_128.png" /><h3>Report Ore</h3><p>Report ore mese corrente e precedente</p></a></li>                
                    </ul>
                </li>
            </ul>
        </div>
        <!--/content-primary -->
 
    </div>
    <!-- /page "menu" -->

    <!-- Start of second page -->
    <div data-role="page" id="FormSpesePage">

        <form id="SpeseForm" method="post" name="SpeseForm">
        
        <div data-role="header">
            <a href="#mainmenu" class='ui-btn-left' data-icon='arrow-l'>Back</a>
            <h1 id="toptitle">
                Inserisci spese</h1>
        </div> <!-- /header -->
        
        <div data-role="content">

            <div class="ui-grid-a"> <!-- Data e importo spesa -->
	      
                <div class="ui-block-a"> 
                    <input name="Tbdate" id="Tbdate" type="date" value='<%=DateTime.Today.ToString("yyyy-MM-dd") %>' placeholder="Inserisci data">
                </div>
	      
                <div class="ui-block-b">
                    <input type="number" name="TbExpenseAmount" ID="TbExpenseAmount" placeholder="Importo spesa" >
                </div>
          
            </div> <!-- /grid-a -->
            
            <br />
            
            <select id="Projects_Id"> <!-- riempito da query --> </select>

            <select id="Spese_Id"> <!-- riempito da query --> </select>
            
            <br />  

            <textarea id="comment" Rows="2" TextMode="MultiLine" placeholder="inserisci un commento se necessario"></textarea>
             
            <fieldset data-role="controlgroup"  data-type="horizontal">
           	    <input type="checkbox" name="CreditCardPayed" id="CreditCardPayed" class="custom" /><label for="CreditCardPayed">CCred</label>                   
                <input type="checkbox" name="InvoiceFlag" id="InvoiceFlag" class="custom" /><label for="InvoiceFlag">Fatt</label>                               
                <input type="checkbox" name="CancelFlag" id="CancelFlag" class="custom" /><label for="CancelFlag">Storno</label>               
            </fieldset>

            <br />
        
            <div class="ui-grid-a"> <!-- Bottoni Form -->
	                <div class="ui-block-a">
        		        <input type="submit" id="SpeseSubmit" value="Salva" data-role="button" data-theme="b" />
                     </div>
	                <div class="ui-block-b">
                	    <input type="button" name="cancel" value="Annulla" data-role="button" onclick="window.location='#mainmenu'" data-theme="b" />
                    </div>
             </div> <!-- /grid-a -->     
        
        </div> <!--/content-primary -->
        
        </form>
     
     </div> <!-- /page #2 form spese -->
	
     <!-- Start of third page -->
     <div data-role="page" id="FormOrePage">

        <form id="OreForm" method="post" name="OreForm">
        
        <div data-role="header">
            <a href="#mainmenu" class='ui-btn-left' data-icon='arrow-l'>Back</a>
            <h1 id="ore_toptitle">
                Inserisci ore</h1>
        </div> <!-- /header -->
        
        <div data-role="content">

            <div class="ui-grid-a">
	            <div class="ui-block-a"> 
                   <input name="TbdateForHours" id="ore_TbdateForHours" type="date" value='<%=DateTime.Today.ToString("yyyy-MM-dd") %>' placeholder="Inserisci data">
                </div>
	            <div class="ui-block-b">
                    <input type="number" name="TbHours" id="ore_TbHours" placeholder="Ore" />
                </div>
            </div><!-- /grid-a -->
            
             <br />
            
            <select id="ore_Projects_Id"> <!-- riempito da query --> </select>

            <select id="ore_TipoOre_Id"> <!-- riempito da query --> </select>
            
            <br />  
             
            <textarea id="ore_comment" Rows="2" TextMode="MultiLine" placeholder="inserisci un commento se necessario"></textarea>
            
            <fieldset data-role="controlgroup"  data-type="horizontal">
                <input type="checkbox" name="TransferFlag" id="ore_TransferFlag" class="custom" /><label for="ore_TransferFlag">&nbsp;&nbsp;Trasferta&nbsp;&nbsp;</label>                   
              	<input type="checkbox" name="CancelFlag" id="ore_CancelFlag" class="custom" /><label for="ore_CancelFlag">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Storno&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>               
            </fieldset>

            <br />    

            <div class="ui-grid-a"> <!-- Bottoni Form -->
	            <div class="ui-block-a">
        		    <input type="submit" id="ore_Submit" value="Salva" data-role="button" data-theme="b" />
                </div>
	             <div class="ui-block-b">
                    <input type="button" id="ore_Cancel" value="Annulla" data-role="button" onclick="window.location='#mainmenu'" data-theme="b" />
                </div>
             </div> <!-- /grid-a -->   

        </div> <!--/content-primary -->
        
        </form>

     </div> <!-- /page FormOrePage -->

</body>
</html>
